package ru.spb.bragnikita.myevents.ajax;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author Nikita.Brazhnikov
 */
@Named("ajax_request")
@RequestScoped
public class RequestAjaxBean {

	private static final Logger logger = Logger.getLogger(RequestAjaxBean.class.getName());

	@Inject
	private AjaxBean ajaxBean;

	private String newValue;

	public void setNewValue(String newValue) {
		this.newValue = newValue;
	}

	public String getNewValue() {
		return newValue;
	}

	public String saveNewValue() {
		logger.log(Level.INFO, "Adding new value {0}", newValue);
		try {
			Thread.sleep(5000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		if (ajaxBean != null)
			ajaxBean.addValue(newValue);
		newValue = null;
		return null;
	}
}
